﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability.Adm;
using EntLibContrib.Query.Properties;

namespace EntLibContrib.Query.Configuration.Manageability.Queries
{
	/// <summary>
	/// Represents the behavior required to provide Group Policy updates and to publish the
	/// <see cref="ConfigurationSetting"/> instances associated to a <see cref="ServiceQueryData"/>.
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public abstract class ServiceQueryDataManageabilityProvider<T>
		: QueryDataManageabilityProvider<T>
		where T : ServiceQueryData
	{
		#region Constants
		/// <summary>
		/// Name for the address property.
		/// </summary>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")]
		public const string AddressKeyName = "address";
		/// <summary>
		/// Name for the service property.
		/// </summary>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")]
		public const string ServiceKeyName = "service";
		/// <summary>
		/// Name for the method property.
		/// </summary>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")]
		public const string MethodKeyName = "method";
		#endregion

		#region Protected Static methods
		/// <summary>
		/// Adds the part to edit the policy overrides for the custom command of a query to the content
		/// built by the <paramref name="contentBuilder"/>.
		/// </summary>
		/// <param name="contentBuilder">The builder for the content where the part will be added.</param>
		/// <param name="address">The address.</param>
		/// <param name="elementPolicyKeyName">Name of the element policy key.</param>
		protected internal static void AddAddressPart(AdmContentBuilder contentBuilder, string address, string elementPolicyKeyName)
		{
			contentBuilder.AddEditTextPart(InternalResources.ServiceQueryAddressPartName,
																		elementPolicyKeyName,
																		AddressKeyName,
																		address,
																		1024,
																		false);
		}

		/// <summary>
		/// Adds the part to edit the policy overrides for the custom command of a query to the content
		/// built by the <paramref name="contentBuilder"/>.
		/// </summary>
		/// <param name="contentBuilder">The builder for the content where the part will be added.</param>
		/// <param name="service">The service.</param>
		/// <param name="elementPolicyKeyName">Name of the element policy key.</param>
		protected internal static void AddServicePart(AdmContentBuilder contentBuilder, string service, string elementPolicyKeyName)
		{
			contentBuilder.AddEditTextPart(InternalResources.ServiceQueryServicePartName,
																		elementPolicyKeyName,
																		ServiceKeyName,
																		service,
																		255,
																		true);
		}

		/// <summary>
		/// Adds the part to edit the policy overrides for the custom command of a query to the content
		/// built by the <paramref name="contentBuilder"/>.
		/// </summary>
		/// <param name="contentBuilder">The builder for the content where the part will be added.</param>
		/// <param name="method">The method.</param>
		/// <param name="elementPolicyKeyName">Name of the element policy key.</param>
		protected internal static void AddMethodPart(AdmContentBuilder contentBuilder, string method, string elementPolicyKeyName)
		{
			contentBuilder.AddEditTextPart(InternalResources.ServiceQueryMethodPartName,
																		elementPolicyKeyName,
																		MethodKeyName,
																		method,
																		255,
																		true);
		}
		#endregion
	}
}
